﻿using System;
using System.ComponentModel;
using System.Linq;
using System.Drawing;
using System.Windows.Forms;
using Interfaces.Update_Interfaces;
using Interfaces.General_Interfaces;
using Interfaces.Inherited_Interfaces;
using Model.Domain_Model;
using Presenters.Update_Presenters;
using Views.Status_Views;

namespace Views
{
    public partial class ClientUpdateView : Form, IClientUpdateView
    {
        ClientUpdatePresenter presenter = null;

        public ClientUpdateView()
        {
            InitializeComponent();
            presenter = new ClientUpdatePresenter(this);
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            presenter.SendDataToView();
        }

        void IParamable.SetParams(params object[] param)
        {
            presenter.client = (Client)param.Where(x => x.GetType() == typeof(Client) || x != null).Take(1).SingleOrDefault();
        }

        T Interfaces.Inherited_Interfaces.IView.ReturnView<T>()
        {
            return (T)((object)this);
        }


        DateTime IClientUpdateView.dateInsert
        {
            get
            {
                return DateTime.Now;
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        string IClientUpdateView.descriptionClient
        {
            get
            {
                return richTextBox1.Text;
            }
            set
            {
                richTextBox1.Text = value as string;
            }
        }

        string IClientUpdateView.email
        {
            get
            {
                return email.Text;
            }
            set
            {
                email.Text = value as string;
            }
        }

        int IClientUpdateView.idClient
        {
            get
            {
                return presenter.client.idClient;
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        string IClientUpdateView.inventedName
        {
            get
            {
                return inventedName.Text;
            }
            set
            {
                inventedName.Text = value as string;
            }
        }

        bool IClientUpdateView.isProtected
        {
            get
            {
                return isProtected.Checked;
            }
            set
            {
                isProtected.Checked = value;
            }
        }

        string IClientUpdateView.nameClient
        {
            get
            {
                return nameClient.Text;
            }
            set
            {
                nameClient.Text = value as string;
            }
        }

        string IClientUpdateView.phoneNumber
        {
            get
            {
                return phoneNumber.Text;
            }
            set
            {
                phoneNumber.Text = value as string;
            }
        }

        string IClientUpdateView.surnameClient
        {
            get
            {
                return surnameClient.Text;
            }
            set
            {
                surnameClient.Text = value as string;
            }
        }


        string IClientUpdateView.nameCorporation
        {
            get
            {
                return nameCorporation.Text;
            }
            set
            {
                nameCorporation.Text = value as string;
            }
        }


        void IError.ShowError()
        {
            presenter.ShowError(new ErrorView());
        }

        void ISuccess.ShowSuccess()
        {
            presenter.ShowSuccess(new SuccessView());
        }

        private void button1_Click(object sender, EventArgs e)
        {
            presenter.Update();
        }

        void ICloseable.Close()
        {
            this.Close();
        }
    }
}
